/*
 * 
 */
package com.pulp.dao;

import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

/**
 * A factory for creating SqlMapClient objects.
 */
public class SqlMapClientFactory {
	
	/** The resource. */
	private String resource = "sql-map-config.xml";

	/** The instance. */
	private static SqlMapClientFactory instance = new SqlMapClientFactory();

	/**
	 * Gets the single instance of SqlMapClientFactory.
	 *
	 * @return single instance of SqlMapClientFactory
	 */
	public static SqlMapClientFactory getInstance() {
		return instance;
	}

	/**
	 * Gets the client.
	 *
	 * @return the client
	 */
	public SqlMapClient getClient() {
		SqlMapClient client = null;
		try {
			Reader reader = Resources.getResourceAsReader(resource);
			client = SqlMapClientBuilder.buildSqlMapClient(reader);
			reader.close();
		} catch (Exception e) {
			throw new RuntimeException("다음과 같은 익셉션발생: SqlMapClient : " + e);
		}

		return client;
	}

	/**
	 * Override properties.
	 *
	 * @param propUrl the prop url
	 */
	public void overrideProperties(String propUrl) {
		this.resource = propUrl;
	}
}
